package com.googlecode.intellimars.mrsp.table;

import jp.sourceforge.mrsp.model.Artifact;

import javax.swing.table.AbstractTableModel;
import java.util.Collections;
import java.util.List;

public class ArtifactListTableModel extends AbstractTableModel {
    private List<Artifact> artifactList;

    public ArtifactListTableModel() {
        artifactList = Collections.EMPTY_LIST;
    }

    public void setArtifactList(List<Artifact> list) {
        artifactList = list;
    }

    public int getRowCount() {
        return artifactList == null ? 0 : artifactList.size();
    }

    public int getColumnCount() {
        return 5;
    }

    public boolean isCellEditable(int row, int column) {
        return false;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Artifact artifact = artifactList.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return artifact.getGroupId();
            case 1:
                return artifact.getArtifactId();
            case 2:
                return artifact.getVersion();
            case 3:
                return artifact.getType();
            case 4:
                return artifact.getRepoUrl();
        }
        throw new ArrayIndexOutOfBoundsException(columnIndex);
    }

    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "groupId";
            case 1:
                return "artifactId";
            case 2:
                return "version";
            case 3:
                return "type";
            case 4:
                return "repository";
        }
        throw new ArrayIndexOutOfBoundsException(column);
    }


    public Artifact getRowValue(int row) {
        return artifactList.get(row);
    }
}
